﻿var _global = this;

(function() {
    function Point(x, y, getXGap, getYGap) {
        this.X = x;
        this.Y = y;
        Point.prototype.GetXGap = getXGap;
        Point.prototype.GetYGap = getYGap;
    }
    _global.Point = Point;

    var radius = 4;
    //var gap = 50;
    var isSelected = false;

    Point.prototype.draw = function(ctx) {
        ctx.beginPath();

        var fs = ctx.fillStyle;
        if (this.isSelected) {
            ctx.fillStyle = "red";
        }
        ctx.arc(this.getXPixels(), this.getYPixels(), radius, 0, 360, false);
        ctx.fill();
        ctx.fillStyle = fs;
    }

    Point.prototype.isHit = function(x, y) {
        var top = ((this.Y + 1) * this.GetYGap()) - radius;
        var bottom = ((this.Y + 1) * this.GetYGap()) + radius;
        var left = ((this.X + 1) * this.GetXGap()) - radius;
        var right = ((this.X + 1) * this.GetXGap()) + radius;

        if (y >= top && y <= bottom && x >= left && x <= right) {
            return true;
        }
        return false;
    }



    Point.prototype.select = function() {
        this.isSelected = !this.isSelected;
    }

    Point.prototype.getXPixels = function() {
        return (this.X + 1) * this.GetXGap();
    }

    Point.prototype.getYPixels = function() {
        return (this.Y + 1) * this.GetYGap();
    }
})();